package com.itheima.reggie.controller;


import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.Category;
import com.itheima.reggie.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @PostMapping
    public R add(@RequestBody Category category) {
        R r = categoryService.add(category);
        return r;
    }

    @GetMapping("/page")
    public R findpage(Integer page, Integer pageSize) {
        R r = categoryService.findpage(page, pageSize);
        return r;
    }

    @DeleteMapping
    public R remove(Long id) {
        R r = categoryService.removeById(id);
        return r;
    }

    @PutMapping
    public R modify(@RequestBody Category category) {
        R r = categoryService.modify(category);
        return r;
    }

    @GetMapping("/list")
    public R list(Integer type){
        R r =categoryService.list(type);
        return r;
    }
}
